package com.smart.test;


import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

/**
 * <p><b>Description:</b>  TODO
 * <p><b>Company:</b>
 *
 * @author created by Jesse Xu at 9:31 on 2019/10/29
 * @version V0.1
 * @classNmae StaticDispatch
 */
public class StaticDispatch {

    static abstract class Human {

    }

    static class Man extends Human {

    }

    static class Women extends Human {

    }

    void sayHello(Human human) {
        System.out.println("hello guys!");
    }
    void sayHello(Man man) {
        System.out.println("hello gentleman!");
    }

    void sayHello(Women women) {
        System.out.println("hello lady!");
    }

    public static void main(String[] args) {
        Women man = new Women();
        StaticDispatch sr = new StaticDispatch();
        try {
            MethodHandle handler = MethodHandles.lookup().findVirtual(sr.getClass(),
                    "sayHello", MethodType.methodType(void.class, Women.class));

            handler.invoke(sr,man);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }
}
